package hrhq.cntvcn.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.apache.solr.client.solrj.SolrServerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import hrhq.cntvcn.pojo.HrhqContent;
import hrhq.cntvcn.pojo.SearchResult;
import hrhq.cntvcn.service.SearchContentService;

@Controller
@RequestMapping({"/search"})
public class SearchArticleController
{
  private static Logger logger = Logger.getLogger(SearchArticleController.class);
  
  @RequestMapping({"/index"})
  public void index(HttpServletRequest req, HttpServletResponse resp)
    throws Exception
  {
    resp.sendRedirect("http://localhost:8081/search/byTitle");
  }
  
  @Autowired
  private SearchContentService scService;
  @RequestMapping({"/byTitle"})
  public String searchByContentTitle(String titleKey,Model model) {
	  long start = System.currentTimeMillis();
	  try {
		SearchResult<HrhqContent> searchResult = scService.searchByContentTitle("元素");
		model.addAttribute("searchResult", searchResult);
	} catch (SolrServerException e) {
		e.printStackTrace();
	}
	  long end = System.currentTimeMillis();
	  System.out.println(end-start);
	  return "searchTest";
  }
}